#include <stdio.h>
#include <unistd.h>
#include <string.h>


#define MOVERIGHT(y) printf("\033[%dC",(y))
#define MOVEDOWN(x) printf("\033[%dB", (x))
#define MOVEUP(x) printf("\033[%dA", (x))
#define MOVELEFT(y) printf("\033[%dD", (y))
#define HIDE_CURSOR() printf("\033[?25l")
#define SHOW_CURSOR() printf("\033[?25h")
#define BULD "\033[44;32m"

void bar()
{
    HIDE_CURSOR();
    int i, j;
    char bar[102];
    memset(bar, 0, 102 * sizeof(char));
    printf("\n");

    i = 0;
    printf(BULD" %-105s \033[0m\n", bar);
    printf("\033[44;32m %s \033[0m\n", bar);
    printf("\033[44;32m %-105s \033[0m\n", bar);
    MOVERIGHT(105);
    MOVEUP(2);
    printf("\033[44;32m %s \033[0m\n", bar);
    printf("\n");
    MOVEUP(2);
    memset(bar, 0, 102 * sizeof(char));
    for (i = 0; i <= 100; i++)
    {
        bar[i] = ' ';
        MOVERIGHT(2);
        printf("\033[41;32m %s \033[0m", bar);

        MOVEDOWN(2);
        if (i < 50) {
            MOVERIGHT(50-i);
        } else {
            if (i == 50) {
                MOVERIGHT(1);
            }
            MOVELEFT(i-50);
        }

        printf("%3d%%", i);
        if (i == 100)
        {
            printf("[COMPLETED]");
        }
        MOVEUP(2);

        printf("\r");
        fflush(stdout);
        usleep(200000);
    }
    printf("\n");
    SHOW_CURSOR();
}

int main()
{
    bar();
    printf("\n");
    printf("\n");
    system("clear");
    return 0;
}
